package com.app.piemoment.entity;

import java.util.List;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.GridView;
import android.widget.AdapterView.OnItemClickListener;

import com.app.piemoment.R;

public class GridDialog extends Dialog {

	public int TYPE;

	private City lastCity = new City();

	public String overCityString = "";

	public City getLastCity() {
		return lastCity;
	}

	public void setLastCity(City lastCity) {
		this.lastCity = lastCity;
	}

	public int getTYPE() {
		return TYPE;
	}

	public void setTYPE(int tYPE) {
		TYPE = tYPE;
	}

	private GridAdapter adapter = null;
	private Context context;
	private List<String> data;
	public GridView gvCityGridView;
	public Button selectAllButton;
	public Button button;
	public Button button2;

	public GridDialog(Context context) {
		super(context);
		this.context = context;
		setContentView(R.layout.city_view);
		gvCityGridView = (GridView) findViewById(R.id.city_gridview);
		selectAllButton = (Button) findViewById(R.id.selectallbutton);
		button = (Button) findViewById(R.id.citydownbutton);
		button2 = (Button) findViewById(R.id.citybackbutton);
	}

	public void refreshData(List<String> cityData, int type, String selectSting) {
		String city = null;
		button2.setVisibility(View.VISIBLE);
		selectAllButton.setVisibility(View.VISIBLE);
		selectSting = "选择" + selectSting;
		if (type == CitySelectDialog.TYPE_PROVINCE) {
			selectAllButton.setText(selectSting);
			setTitle(CitySelectDialog.provinceString);
			button2.setVisibility(View.GONE);
			city = lastCity.getProvince();
		} else if (type == CitySelectDialog.TYPE_CITY) {
			selectAllButton.setText(selectSting);
			setTitle(CitySelectDialog.cityString);
			city = lastCity.getCity();
		} else if (type == CitySelectDialog.TYPE_TOWN) {
			selectAllButton.setText(selectSting);
			setTitle(CitySelectDialog.townString);
			city = lastCity.getTown();
		}
//		else if (type == SelectDialog.TYPE_CAR) {
//			setTitle(SelectDialog.cartypeString);
//			button2.setVisibility(View.GONE);
//			selectAllButton.setVisibility(View.GONE);
//		} else if (type == SelectDialog.TYPE_UNIT) {
//			setTitle(SelectDialog.unitString);
//			button2.setVisibility(View.GONE);
//			selectAllButton.setVisibility(View.GONE);
//
//		}
		adapter = new GridAdapter(context);
		adapter.setGridItem(cityData, city);
		gvCityGridView.setTag(type);
		gvCityGridView.setAdapter(adapter);

	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}

	public void setOnItemListener(OnItemClickListener iocl) {
		gvCityGridView.setOnItemClickListener(iocl);
	}

	public void setButtonOnClick(android.view.View.OnClickListener bocl) {
		button.setOnClickListener(bocl);
		button2.setOnClickListener(bocl);
		selectAllButton.setOnClickListener(bocl);
	}
}